import time
from locust import HttpUser, task, between
import requests,json

class QuickstartUser(HttpUser):
    wait_time = between(0.1, 0.2)
    # wait_time = constant(0)

    def on_start(self):
        headers = {
            "Authorization": "",
            "Content-Type": "application/json"
        }
        payload = json.dumps({
            "clientId": "frontend",
            "grantType": "password",
            "username": "admin_123",
            "password": "d6bf4bb9a66419380a7e8b034270d381"
        })

        r = requests.post(url='http://180.76.36.251:9005/v2xapp/user/login', headers=headers, data=payload,
                          verify=False).text
        r_dict = json.loads(r)
        self.token = r_dict['data']["accessToken"]

    @task
    def user_info1(self):
        self.headers = {
            "accessToken": self.token
        }
        self.client.get("/v2xapp/user/userInfo", headers=self.headers)

    @task(3)
    def user_info2(self):
        self.headers = {
            "accessToken": self.token
        }
        self.client.get("/v2xapp/user/userInfo", headers=self.headers)

    # def on_start(self):
    #     self.client.post("/login", json={"username":"foo", "password":"bar"})


